package cn.yuyiling.jelly.sr.controller;

import cn.yuyiling.jelly.sr.api.LearningProgressService;
import cn.yuyiling.jelly.sr.api.RankService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/learning")
public class LearningProgressController {
    private static final Logger logger = LoggerFactory.getLogger(LearningProgressController.class);

    @DubboReference(scope = "remote")
    private LearningProgressService learningProgressService;
    @DubboReference(scope = "remote")
    private RankService rankService;

    /**
     * 记录知识点学习开始
     */
    @PostMapping("/study-kg/start")
    public String startStudySession(@RequestParam String userId,
                                    @RequestParam String knowledgePointId) {
        return learningProgressService.recordStudySession(userId, knowledgePointId);
    }

    /**
     * 记录知识点学习结束
     */
    @PostMapping("/study-kg/end")
    public void endStudySession(@RequestParam String sessionId) {
        learningProgressService.endStudySession(sessionId);
    }

    /**
     * 记录答题结果
     */
    @PostMapping("/answer/start")
    public String startAnswerSession(@RequestParam String userId,
                                     @RequestParam String answerId) {
        return learningProgressService.recordAnswerSession(userId, answerId);
    }

    @PostMapping("/answer/end")
    public String endAnswerSession(@RequestParam String sessionId,
                                   @RequestParam int score) {
        return learningProgressService.recordAnswerResult(sessionId, score);
    }

    @GetMapping("/duration/daily/{userId}")
    public Map<String, Integer> getDailyDuration(@PathVariable String userId) {
        return learningProgressService.getDailyStudyDuration(userId);
    }

    @GetMapping("/duration/weekly/{userId}")
    public Map<String, Integer> getWeeklyDuration(@PathVariable String userId) {
        return learningProgressService.getWeeklyStudyDuration(userId);
    }

    @GetMapping("/duration/monthly/{userId}")
    public Map<String, Integer> getMonthlyDuration(@PathVariable String userId) {
        return learningProgressService.getMonthlyStudyDuration(userId);
    }
}